package mapEditor.view.assetEdit
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	import mapEditor.vo.AssetVO;
	
	import utils.ApplicationDomainUtil;
	import utils.DisplayUtil;

	public class AssetEditItemView extends Sprite
	{
		private var _assetObject:DisplayObject;
		private var _assetVO:AssetVO;
		
		public function AssetEditItemView(assetVO:AssetVO)
		{
			_assetVO=assetVO;
			loadAsset();
		}
		
		private function loadAsset():void
		{
			var obj:*=ApplicationDomainUtil.getDefinitionObject(_assetVO.className);
			if(obj is BitmapData)
			{
				_assetObject=new Bitmap(obj);
			}
			else if(obj is MovieClip)
			{
				_assetObject=obj as DisplayObject;
			}
			addChild(_assetObject);
		}
		
		private function clearAsset():void
		{
			_assetVO=null;
			DisplayUtil.dispose(_assetObject);
			_assetObject=null;
		}
		
		public function dispose():void
		{
			_assetVO=null;
			clearAsset();
			if(parent)parent.removeChild(this);
		}

		public function get assetVO():AssetVO
		{
			return _assetVO;
		}
	}
}